<!--
 * @Author: lmk
 * @Date: 2021-11-24 15:03:13
 * @LastEditTime: 2021-12-03 19:09:52
 * @LastEditors: lmk
 * @Description: 
-->
<template>
	<view :class="currentTheme">
		<a-nabbar name=" " :isBack="false" navBg="transparent"/>
		<view class="welcome u-flex  u-row-between">
			<view class="img-box img1">
				<image
					src="https://larp-gbo.oss-cn-chengdu.aliyuncs.com/larp/common-light/chooseType.png">
				</image>
			</view>
			<view class="img-box img2">
				<image
					src="https://larp-gbo.oss-cn-chengdu.aliyuncs.com/larp/common-light/chooseTypeBg.png">
				</image>
			</view>
		</view>
		<view class="select-box">
			<view v-for="(item,index) in roles" :key="index" class="u-margin-bottom-20" @click="setUserType(item.userType)">
				<item-image :img="`${aliosCdn}/larp/common-${currentTheme}/${item.userType}.png`" height="208" width="686"></item-image>
			</view>
		</view>
		<view class="u-flex u-row-center btn-box">
			<view class="text-color-txtTheme u-font-32"  @click="goIndex">先逛逛</view>
			<!-- <item-btn block height="88"  @click="goIndex">先逛逛</item-btn> -->
		</view>
		<model v-model="confirmFlag" :show-title="false" @confirm="setUser" show-cancel-button 
		 cancel-color="#333333" :confirm-color="currentThemeObj.primary" :content="`是否确认注册为${selectIndex=='issue'?'发行':'商家'}？`" />
	</view>
</template>

<script>
	import model from '@/components/u-modal/u-modal.vue'
	import {
		updateUserType
	} from '@/api/user.js'
	export default {
		data() {
			return {
				selectIndex: null,
				confirmFlag: false,
				roles:[{
					userType:"issue"
				},{
					userType:"store"
				},{
					userType:"DMDZ"
				}]
			};
		},
		components: {
			model
		},
		methods: {
			//弹框验证身份
			setUserType(userType) {
				if(userType!='DMDZ'){
					this.selectIndex = userType;
					this.confirmFlag = true;
				}else{
					this.goIndex()
				}
			},
			//设置身份并跳转到完善信息
			async setUser() {
				try {
					await this.updateUserType()
					this.$u.route({
						url: '/pagesA/setting/setting',
						params: {
							userType: this.selectIndex,
							firstLogin: true
						}
					})
				} catch (e) {
					//TODO handle the exception
				}
			},
			//直接跳转index
			async goIndex() {
				try {
					await this.updateUserType()
					this.$u.route({
						type: "reLaunch",
						url: '/pages/index/index'
					})
				} catch (e) {
					//TODO handle the exception
				}
			},
			updateUserType() {
				//首次登录首先需要设置身份
				return updateUserType({
					uid: this.loginForm.uid,
					operationStep: 1, //设置用户步骤
					userType: this.selectIndex
				})
			}
		},
	}
</script>
<style lang="scss" scoped>
	.btn-box{
		margin-top: 10rpx;
		padding-left: 32rpx;
		padding-right: 32rpx;
	}
	.select-box{
		padding: 0 32rpx 32rpx;
	}
		.welcome {
		// position: fixed;
		// left: 50rpx;
		// width: 466rpx;
		// height: 290rpx;
		margin: 0 108rpx -6rpx 50rpx;
		// padding-top: 40rpx;
		.img1{
			image{
				width: 220rpx;
				height: 238rpx;
			}
		}
		.img2{
			image{
				width: 256rpx;
				height: 352rpx;
			}
		}
	}
</style>
